package com.cg.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * @Author: cg
 * @Date: Create IN 2017/6/26 17:49
 * @Email: cg_666666@163.com
 */
@Configuration
@EnableSwagger2
public class Swagger2Configuration {
    @Bean
    public Docket accessToken(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("test") //定义组
                .select() //选择那些路径和api会生成document
                .apis(RequestHandlerSelectors.basePackage("com.cg.controller")) //拦截包路径
                .paths(regex("/test/.*")) //拦截的接口路径
                .build() //创建
                .apiInfo(apiInfo());//配置说明
    }

    private ApiInfo apiInfo(){
      return new ApiInfoBuilder()
              .title("果鑫科技")
              .description("项目外包")
              .termsOfServiceUrl("www.lovecg.cn")
              .contact(new Contact("cg","www.lovecg.cn","cg_666666@163.com"))
              .license("Apache license Version 2.0") //开源协议
              .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
              .version("1.0")
              .build();
    }
}
